package com.bbs.toutiao.mapper.admin;

import com.bbs.toutiao.entity.UserEntity;
import com.bbs.toutiao.vo.user.RegisterVo;
import com.bbs.toutiao.vo.user.UpdateStatusVo;
import com.bbs.toutiao.vo.user.UserRequestPageVo;
import com.bbs.toutiao.vo.user.UserResponseVo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface UserMapper {


    /**
     * 根据用户账号以及密码查询
     **/
    @Select("select * from t_users where user_email like #{email} and password  like #{password}")
    UserEntity login(String email, String password);

    /**
     * 用户注册
     **/
    @Insert("insert into t_users (username,user_email,password,account,phone) values (#{userName},#{email},#{password},#{account},#{phone})")
    int register(RegisterVo registerVo);


    //动态查询用户数量
    long findUserCount(UserRequestPageVo searchVo);

    //更新用户状态
    @Update("update t_users set status = #{status},ban_end_time = #{BanEndTime}  where id =#{id} and account =#{account}")
    Integer updateStatus(UpdateStatusVo statusVo);

    //查询邮箱是否被注册
    @Select("select count(user_email) from  t_users where user_email like #{email} ")
    int findUserByEmail(String email);

    //分页查询用户
    List<UserResponseVo> findByUserSearchPage(UserRequestPageVo searchVo);



    //根据id查询用户所有信息
    @Select("select * from t_users where id=#{id}")
    UserEntity userInfoById(Integer id);

    //判断是否续约
    @Select("select id,ban_end_time,status from t_users where id=#{id}")
    UserEntity getUserTimeById(Integer id);

    //根据用户id统计收藏夹数量
    @Select("select count(*) from t_favorites where user_id=#{id}")
    int favoritesCount(int id);

    //动态更新用户
    int updateUserInfoById(UserEntity user);
}
